import 'package:base_flutter/base_flutter.dart';
import 'package:ls_work/net/post_request.dart';
import 'package:ls_work/net/response/food/old_food_order_response.dart';
import 'package:ls_work/net/response/response_data.dart';

import '../../net/api/http_api.dart';
import '../../net/response/food/week_order_info_data.dart';

class FoodRecordModel extends BaseMvvmModel {
  @override
  void onCleared() {}

  Future<OldFoodOrderResponse> getOldOrderDetail(String elderHumanId,
      {String startDate = "", String showDay = "30"}) async {
    var map = {
      "elderHumanId": elderHumanId,
      "startDate": startDate,
      "showDay": showDay
    };
    var data = await HttpGo.instance.postData(BookFoodApis.oldOrderRecord,
        data: map.toJsonMapStr(), options: PostRequest.urlencodedHeader);
    if ("0" == data['code']) {
      var bean = OldFoodOrderResponse.fromJson(data);
      return bean;
    } else {
      throw data['msg'];
    }
  }

  Future<ResponseBean> cancelFood(dynamic id) async {
    var map = {"id": id,"dataFrom":"2"};
    var data = await HttpGo.instance.postData(BookFoodApis.cancelFood,
        data: map.toJsonMapStr(), options: PostRequest.urlencodedHeader);
    if ("0" == data['code']) {
      var bean = ResponseBean.fromJson(data);
      return bean;
    } else {
      throw data['msg'];
    }
  }

  ///取周预定信息
  Future<WeekOrderInfoData> weekOrderInfo(String id) async {
    var map = {
      "id":id
    };
    var data = await HttpGo.instance.postData(BookFoodApis.weekOrderInfo,
        data: map.toJsonMapStr(), options: PostRequest.urlencodedHeader);
    if ("0" == data['code']) {
      var bean = ResponseBean.fromJson(data);
      var infp = WeekOrderInfoData.fromJson(bean.data);
      return infp;
    } else {
      throw data['msg'];
    }
  }
}
